<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Team extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = ['name', 'description'];

    public function users()
    {
        return $this->belongsToMany(User::class);
    }

    public function domain()
    {
        return $this->belongsTo(Domain::class, 'domain_id');
    }

    public function links()
    {
        return $this->hasMany(TeamLink::class, 'team_id');
    }

    public function tasks()
    {
        return $this->hasMany(Task::class, 'team_id');
    }

    public function hirings()
    {
        return $this->hasMany(Hiring::class, 'team_id');
    }

    public function roles()
    {
        return $this->hasMany(DomainRole::class, 'domain_id');
    }

    public function chatMessages()
    {
        return $this->morphMany(ChatMessage::class, 'message_parent_model');
    }
}
